<?php defined('BASE_PATH') or die('No direct script access.');
/**
 * Gialac php framework
 * Language Library
 * @package    libraries
 * @category   Language
 * @author     Gialachoanglong
 * @copyright  (c) 2011
 */
final class Language {
    private $lang;
    private $position;
    private $data = array();
    public function __construct($lang,$position) {
        $this->lang = $lang;
        $this->position=$position;
        self::load(FALSE,TRUE);
    }
    public function get($key) {
        return (isset($this->data[$key]) ? $this->data[$key] : $key);
    }
    public function load($filename=FALSE,$replace=FALSE) {
        $_ = array();
        if($replace==TRUE) {
            $default = BASE_PATH . '/application/languages/english.php';
            if (file_exists($default)) {
                require($default);
            }
            $file=BASE_PATH .'/application/languages/'.$this->lang.'.php';
        }else {
            $default = MODULE.$filename. '/languages/english/'.$this->position.'.php';
            if (file_exists($default)) {
                require($default);
            }
            $file=MODULE.$filename. '/languages/'.$this->lang.'/'.$this->position.'.php';
        }
        if (file_exists($file) && $file != $default) {
            require($file);
        }

        $this->data = array_merge($this->data, $_);
        return $this->data;
    }
}
?>